﻿@model HQPad.Models.ArmourItem

@{
    ViewBag.Title = "Edit Armour";
    Layout = "~/Views/Shared/_ModalLayout.cshtml";
    List<HQPad.Models.ArmourSelectType> armours = (List<HQPad.Models.ArmourSelectType>) ViewBag.ArmourTypes;
}

<script src="@Url.Content("~/Scripts/jquery-ui-1.10.3.custom.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/global.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/armour.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var superior = @Html.Raw(Model != null ? Model.Superior.ToString() : "0");
        var empowered = @Html.Raw(Model != null ? Model.Empowered.ToString() : "0");
        var ensorcelled = @Html.Raw(Model != null ? Model.Ensorcelled.ToString() : "0");
        
        $('.superiorSlider').slider({ 
            min: 0, 
            max: 3, 
            value: superior,
            slide: function(event, ui) {  
                if (ui.value > 0)
                    $('.superiorValue').html('+' + ui.value.toString());
                else
                    $('.superiorValue').html('(not superior)');

                $('#itemSuperior').val(ui.value);
            }
        });
        $('.empoweredSlider').slider({ 
            min: 0, 
            max: 10, 
            value: empowered,
            slide: function(event, ui) {  
                if (ui.value > 0)
                    $('.empoweredValue').html('+' + ui.value.toString());
                else
                    $('.empoweredValue').html('(not empowered)');

                $('#itemEmpowered').val(ui.value);
            }
        });
        $('.ensorcelledSlider').slider({ 
            min: 0, 
            max: 10, 
            value: ensorcelled,
            slide: function(event, ui) {  
                if (ui.value > 0)
                    $('.ensorcelledValue').html('+' + ui.value.toString());
                else
                    $('.ensorcelledValue').html('(not ensorcelled)');

                $('#itemEnsorcelled').val(ui.value);
            }
        });

        $('.edit-armour-form').armour({
            updateArmourItemUrl: '@Url.Action("UpdateArmour", new { id = Model != null ? (int?)Model.Id : null })',    // service url of update armour ajax call.
            updateArmourCallback: function () {
                parent.closeModalAndRefresh();
            }
        });
    });
</script>

<h1>Armour</h1>

<div class="message-box"></div>

<section class="modal-content">
    <div class="edit-armour form">
        @using (Html.BeginForm("EditArmour", "Character", FormMethod.Post, new { @name = "editArmourForm", @id = "editArmourForm" }))
        {
            <input type="hidden" id="itemId" name="itemId" value="@Html.Raw(Model != null ? Model.Id.ToString() : "")" />  
            if (Model == null)
            {
            <div class="field-item">
                <div class="label"><label for="itemName">Type:</label></div>
                @Html.DropDownListFor(m => m.Type, new SelectList(armours, "Type", "Description"), new { id = "armourType"})
            </div>
            }
            else
            {
                @Html.HiddenFor(m => m.Type, new { id = "armourType"})
            }
            <div class="field-item">
                <div class="label"><label for="itemName">Name:</label></div>
                @Html.TextBoxFor(m => m.ItemName, new { @class = "textbox textbox-wide", id = "itemName" })
            </div>
            <div class="field-item">
                <div class="label"><label for="hqId">HQ ID:</label></div>
                @Html.TextBoxFor(m => m.HQId, new {@class="textbox textbox-narrow", id = "itemHQID"})
            </div>
            <div class="field-item">
                <div class="label label-wide"><label for="itemSuperior">Superior: <span class="superiorValue value">@Html.Raw(Model != null && Model.Superior > 0 ? "+" + Model.Superior : "(not superior)")</span></label></div>
                <div class="slider">
                    <div class="superiorSlider"></div>
                </div>
                @Html.HiddenFor(m => m.Superior, new { @class = "itemSuperior", id = "itemSuperior" })
            </div>
            <div class="field-item">
                <div class="label label-wide"><label for="itemEmpowered">Empowered: <span class="empoweredValue value">@Html.Raw(Model != null && Model.Empowered > 0 ? "+" + Model.Empowered : "(not empowered)")</span></label></div>
                <div class="slider">
                    <div class="empoweredSlider"></div>
                </div>
                @Html.HiddenFor(m => m.Empowered, new { @class = "itemEmpowered", id = "itemEmpowered" })
            </div>
            <div class="field-item">
                <div class="label label-wide"><label for="itemEnsorcelled">Ensorcelled: <span class="ensorcelledValue value">@Html.Raw(Model != null && Model.Ensorcelled > 0 ? "+" + Model.Ensorcelled : "(not ensorcelled)")</span></label></div>
                <div class="slider">
                    <div class="ensorcelledSlider"></div>
                </div>
                @Html.HiddenFor(m => m.Ensorcelled, new { @class = "itemEnsorcelled", id = "itemEnsorcelled" })
            </div>
            <input type="submit" value="Update" />
        }
    </div>
</section>

